package com.ruoyi.web.course;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.vo.TVideoCategoryVo;
import com.ruoyi.course.service.ITVideoCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 视频分类Controller
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@Api(tags = "视频分类Controller")
@RestController
@RequestMapping("/course/category")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TVideoCategoryController extends BaseController {

    private final ITVideoCategoryService tVideoCategoryService;

    @ApiOperation("查询视频分类列表")
    @PreAuthorize("@ss.hasPermi('course:category:list')")
    @GetMapping("/list")
    public TableDataInfo<TVideoCategoryVo> list(TVideoCategoryVo entity) {
        return tVideoCategoryService.queryList(entity);
    }

    @ApiOperation("查询视频分类所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TVideoCategoryVo entity) {
        return AjaxResult.success("查询成功", tVideoCategoryService.queryAll(entity));
    }

    @ApiOperation("导出视频分类列表")
    @PreAuthorize("@ss.hasPermi('course:category:export')")
    @Log(title = "视频分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TVideoCategoryVo entity) {
        List<TVideoCategoryVo> list = tVideoCategoryService.queryAll(entity);
        ExcelUtil<TVideoCategoryVo> util = new ExcelUtil<>(TVideoCategoryVo.class);
        util.exportExcel(response, list, "视频分类数据");
    }

    @ApiOperation("获取视频分类详细信息")
    @PreAuthorize("@ss.hasPermi('course:category:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tVideoCategoryService.queryById(id));
    }

    @ApiOperation("新增视频分类")
    @PreAuthorize("@ss.hasPermi('course:category:add')")
    @Log(title = "视频分类", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TVideoCategoryVo entity) {
        return toAjax(tVideoCategoryService.save(entity));
    }

    @ApiOperation("修改视频分类")
    @PreAuthorize("@ss.hasPermi('course:category:edit')")
    @Log(title = "视频分类", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TVideoCategoryVo entity) {
        return toAjax(tVideoCategoryService.updateById(entity));
    }

    @ApiOperation("删除视频分类")
    @PreAuthorize("@ss.hasPermi('course:category:remove')")
    @Log(title = "视频分类", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tVideoCategoryService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
